home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / str2bmp / test.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  8.8 KB  |  284 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00FF0000&
  4.    Caption         =   "Bitmap Function Tester."
  5.    ClientHeight    =   4050
  6.    ClientLeft      =   1860
  7.    ClientTop       =   2190
  8.    ClientWidth     =   7245
  9.    ClipControls    =   0   'False
  10.    Height          =   4455
  11.    Left            =   1800
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   4050
  14.    ScaleWidth      =   7245
  15.    Top             =   1845
  16.    Width           =   7365
  17.    Begin CommandButton CommandCopyResultToB 
  18.       Caption         =   "Copy RESULT to B"
  19.       Height          =   555
  20.       Left            =   5040
  21.       TabIndex        =   12
  22.       Top             =   1380
  23.       Width           =   2055
  24.    End
  25.    Begin CommandButton CommandAnd 
  26.       Caption         =   "RESULT = A AND B"
  27.       Height          =   555
  28.       Left            =   5040
  29.       TabIndex        =   11
  30.       Top             =   780
  31.       Width           =   2055
  32.    End
  33.    Begin PictureBox PictureResult 
  34.       AutoRedraw      =   -1  'True
  35.       BorderStyle     =   0  'None
  36.       Height          =   615
  37.       Left            =   3240
  38.       ScaleHeight     =   41
  39.       ScaleMode       =   3  'Pixel
  40.       ScaleWidth      =   81
  41.       TabIndex        =   7
  42.       Top             =   2820
  43.       Width           =   1215
  44.    End
  45.    Begin CommandButton CommandOr 
  46.       Caption         =   "RESULT = A OR B"
  47.       Height          =   555
  48.       Left            =   5040
  49.       TabIndex        =   6
  50.       Top             =   180
  51.       Width           =   2055
  52.    End
  53.    Begin CommandButton CommandInvertA 
  54.       Caption         =   "Invert A"
  55.       Height          =   555
  56.       Left            =   5040
  57.       TabIndex        =   5
  58.       Top             =   3180
  59.       Width           =   2055
  60.    End
  61.    Begin CommandButton CommandCompareAtoB 
  62.       Caption         =   "Compare A to B"
  63.       Height          =   555
  64.       Left            =   5040
  65.       TabIndex        =   4
  66.       Top             =   2580
  67.       Width           =   2055
  68.    End
  69.    Begin PictureBox PictureA 
  70.       AutoRedraw      =   -1  'True
  71.       BorderStyle     =   0  'None
  72.       Height          =   615
  73.       Left            =   360
  74.       ScaleHeight     =   41
  75.       ScaleMode       =   3  'Pixel
  76.       ScaleWidth      =   81
  77.       TabIndex        =   3
  78.       Top             =   2820
  79.       Width           =   1215
  80.    End
  81.    Begin PictureBox PictureB 
  82.       AutoRedraw      =   -1  'True
  83.       BorderStyle     =   0  'None
  84.       Height          =   615
  85.       Left            =   1800
  86.       ScaleHeight     =   41
  87.       ScaleMode       =   3  'Pixel
  88.       ScaleWidth      =   81
  89.       TabIndex        =   2
  90.       Top             =   2820
  91.       Width           =   1215
  92.    End
  93.    Begin CommandButton CommandCopyAtoB 
  94.       Caption         =   "Copy A to B"
  95.       Height          =   555
  96.       Left            =   5040
  97.       TabIndex        =   1
  98.       Top             =   1980
  99.       Width           =   2055
  100.    End
  101.    Begin CommandButton CommandDrawCircle 
  102.       Caption         =   "Draw Circles in A"
  103.       Height          =   555
  104.       Left            =   600
  105.       TabIndex        =   0
  106.       Tag             =   "Write line to A"
  107.       Top             =   600
  108.       Width           =   3495
  109.    End
  110.    Begin Label Label3 
  111.       BackColor       =   &H00FF0000&
  112.       Caption         =   "A"
  113.       FontBold        =   -1  'True
  114.       FontItalic      =   0   'False
  115.       FontName        =   "MS Sans Serif"
  116.       FontSize        =   12
  117.       FontStrikethru  =   0   'False
  118.       FontUnderline   =   0   'False
  119.       ForeColor       =   &H00FFFFFF&
  120.       Height          =   255
  121.       Left            =   840
  122.       TabIndex        =   10
  123.       Top             =   3540
  124.       Width           =   255
  125.    End
  126.    Begin Label Label2 
  127.       BackColor       =   &H00FF0000&
  128.       Caption         =   "B"
  129.       FontBold        =   -1  'True
  130.       FontItalic      =   0   'False
  131.       FontName        =   "MS Sans Serif"
  132.       FontSize        =   12
  133.       FontStrikethru  =   0   'False
  134.       FontUnderline   =   0   'False
  135.       ForeColor       =   &H00FFFFFF&
  136.       Height          =   255
  137.       Left            =   2280
  138.       TabIndex        =   9
  139.       Top             =   3600
  140.       Width           =   255
  141.    End
  142.    Begin Label Label1 
  143.       BackColor       =   &H00FF0000&
  144.       Caption         =   "Result"
  145.       FontBold        =   -1  'True
  146.       FontItalic      =   0   'False
  147.       FontName        =   "MS Sans Serif"
  148.       FontSize        =   12
  149.       FontStrikethru  =   0   'False
  150.       FontUnderline   =   0   'False
  151.       ForeColor       =   &H00FFFFFF&
  152.       Height          =   255
  153.       Left            =   3480
  154.       TabIndex        =   8
  155.       Top             =   3540
  156.       Width           =   855
  157.    End
  158. Option Explicit
  159. ' Strings to hold pixel information.
  160. Dim A$
  161. Dim B$
  162. Dim RESULT$
  163. Sub CommandAnd_Click ()
  164.   Dim bytes As Long
  165.   Dim ret%
  166.   bytes = BMP_GetSize(PictureA.Image)
  167.   If (bytes = 0) Then
  168.      MsgBox ("Bitmap too large to store!")
  169.      End
  170.   End If
  171.   A$ = Space$(bytes)
  172.   B$ = Space$(bytes)
  173.   RESULT$ = Space$(bytes)
  174.   ret% = BMPToString(PictureA.hDC, PictureA.Image, A$)
  175.   ret% = BMPToString(PictureB.hDC, PictureB.Image, B$)
  176.   bytes = StringBMP_and(A$, B$, RESULT$)
  177.   ret% = StringToBmp(RESULT$, PictureResult.hDC, PictureResult.Image)
  178.   PictureResult.Refresh
  179. End Sub
  180. Sub CommandCompareAtoB_Click ()
  181.   Dim bytes As Long
  182.   Dim A$, B$
  183.   Dim ret%
  184.   bytes = BMP_GetSize(PictureA.Image)
  185.   If (bytes = 0) Then
  186.      MsgBox ("Bitmap too large to store!")
  187.      End
  188.   End If
  189.   A$ = Space$(bytes)
  190.   B$ = Space$(bytes)
  191.   ret% = BMPToString(PictureA.hDC, PictureA.Image, A$)
  192.   If BMP_GetSize(PictureB.Image) <> bytes Then
  193.      MsgBox "Bitmaps must be same size to compare. "
  194.      End
  195.   End If
  196.   ret% = BMPToString(PictureB.hDC, PictureB.Image, B$)
  197.   bytes = StringBMP_Compare(A$, B$)
  198.   MsgBox "This difference is " + Str$(bytes) + " pixels."
  199. End Sub
  200. Sub CommandCopyAtoB_Click ()
  201.   Dim ret%
  202.   B$ = A$
  203.   ' Fill PictureBox with information in B$
  204.   ret% = StringToBmp(B$, PictureB.hDC, PictureB.Image)
  205.   ' Display the new information
  206.    PictureB.Refresh
  207. End Sub
  208. Sub CommandCopyResultToB_Click ()
  209.   Dim ret%
  210.   ' Copy RESULT to B (STRINGS!)
  211.   B$ = RESULT$
  212.   ' Convert the new B$ to a picture and display it!
  213.   ret% = StringToBmp(B$, PictureB.hDC, PictureB.Image)
  214.   PictureB.Refresh
  215. End Sub
  216. Sub CommandDrawCircle_Click ()
  217.   Dim ret%
  218.   Dim bytes As Long
  219.   ' Draw a black circle
  220.   PictureA.FillStyle = 0
  221.   PictureA.FillColor = RGB(0, 0, 0)
  222.   PictureA.Circle (10, 10), 5, RGB(0, 0, 0)
  223.   PictureA.FillColor = RGB(255, 0, 0)
  224.   PictureA.Circle (40, 25), 5, RGB(255, 0, 0)
  225.   PictureA.FillColor = RGB(0, 255, 0)
  226.   PictureA.Circle (25, 30), 5, RGB(0, 255, 0)
  227.   ' Determine the size of a string required to hold PictureA
  228.   bytes = BMP_GetSize(PictureA.Image)
  229.   If (bytes = 0) Then
  230.      MsgBox ("Bitmap too large to store as a string!")
  231.      End
  232.   End If
  233.   ' Create a string of the proper size to hold picture box.
  234.   A$ = Space$(bytes)
  235.   ' Convert PictureA into A$
  236.   ret% = BMPToString(PictureA.hDC, PictureA.Image, A$)
  237. End Sub
  238. Sub CommandInvertA_Click ()
  239.   Dim bytes As Long
  240.   Dim ret%
  241.   Dim TEMP$
  242.   ' Determine the size of a string required to hold PictureA
  243.   bytes = BMP_GetSize(PictureA.Image)
  244.   If (bytes = 0) Then
  245.      MsgBox ("Bitmap too large to store!")
  246.      End
  247.   End If
  248.   ' Make sure space is allocated to hold all pixels in strings.
  249.   A$ = Space$(bytes)
  250.   TEMP$ = Space$(bytes)
  251.                               
  252.   ' Copy PictureA into A$
  253.   ret% = BMPToString(PictureA.hDC, PictureA.Image, A$)
  254.   ' Invert A$ and store the result in RESULT$
  255.   ret% = StringBMP_Invert(A$, TEMP$)
  256.   A$ = TEMP$
  257.   ' Convert A$ into a picture box and display.
  258.   ret% = StringToBmp(A$, PictureA.hDC, PictureA.Image)
  259.   PictureA.Refresh
  260. End Sub
  261. Sub CommandOr_Click ()
  262.   Dim bytes As Long
  263.   Dim ret%
  264.   ' Make sure strings are correct size to hold bitmap info.
  265.   '  The following code works only if all three bitmaps are the
  266.   '  same size.
  267.   bytes = BMP_GetSize(PictureA.Image)
  268.   If (bytes = 0) Then
  269.      MsgBox ("Bitmap too large to store!")
  270.      End
  271.   End If
  272.   A$ = Space$(bytes)
  273.   B$ = Space$(bytes)
  274.   RESULT$ = Space$(bytes)
  275.   ' Fill A$ and B$ with the bitmaps in PictureA and PicutreB, respectively.
  276.   ret% = BMPToString(PictureA.hDC, PictureA.Image, A$)
  277.   ret% = BMPToString(PictureB.hDC, PictureB.Image, B$)
  278.   ' Or the pixels in A$ with those in B$ to create RESULT$
  279.   bytes = StringBMP_Or(A$, B$, RESULT$)
  280.   ' Convert the RESULT$ into a picture box and display it.
  281.   ret% = StringToBmp(RESULT$, PictureResult.hDC, PictureResult.Image)
  282.   PictureResult.Refresh
  283. End Sub
  284.